<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 数组转Set

    // (1) 手动转换
    var arr = [1, 2, 3, 3, 2, 1, 1, 3, 2, 2, 1, 3];

    var s = new Set();
    // arr.forEach(function (val, index, array) { })
    // arr.forEach(function (v) { return s.add(v) })
    // arr.forEach((v) => { return s.add(v) })
    // arr.forEach(v => { return s.add(v) })
    arr.forEach(v => s.add(v))
    console.log(s);

    // (2) new Set() 可以直接接收一个数组 => 返回去重后的Set结构

    var arr = [1, 2, 3, 3, 2, 1, 1, 3, 2, 2, 1, 3];
    var s = new Set(arr);
    console.log(s);


    // Set结构转数组
    // (1) 手动转换
    // var list = [];
    // s.forEach(v => list.push(v));
    // console.log(list);

    // (2) 借助 Array.from()   ... 
    var list = Array.from(s);
    console.log(list);
    var list = [...s];
    console.log(list);


    // 数组去重
    var arr = [1, 2, 3, 3, 2, 1, 1, 3, 2, 2, 1, 3];
    var list = [...new Set(arr)];
    console.log(list);








</script>

</html>